<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <title>轨迹回放</title>
    <link rel="stylesheet" type="text/css" href="../static/css/header.css"/>
    <link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css"/>
    <style>
        html, body, #container {
            height: 100%;
            width: 100%;
        }

        .input-card .btn{
            margin-right: 1.2rem;
            width: 9rem;
        }

        .input-card .btn:last-child{
            margin-right: 0;
        }
    </style>
</head>
<body>
<!--    导航栏开始  -->
<div class="header">
    <div class="header-inner">
        <ul class="header_left">
            <li class="logo">
                汽车出行
            </li>
            <li></li>
        </ul>
        <div class="header_right">
            <ul role="menubar" class="el-menu-demo"
                style="background-color: rgb(24, 27, 44);">
                <li role="menuitem" tabindex="0" class="el-menu-item is-active"
                    style="color: rgb(255, 255, 255); ">
                    概览
                </li>
                <li role="menuitem" tabindex="0" class="el-menu-item"
                    style="color: rgb(255, 255, 255); border-bottom-color: transparent; background-color: rgb(24, 27, 44);">
                    订单监控
                </li>
                <li role="menuitem" tabindex="0" class="el-menu-item"
                    style="color: rgb(255, 255, 255); border-bottom-color: transparent; background-color: rgb(24, 27, 44);">
                    轨迹监控
                </li>
                <li role="menuitem" tabindex="0" class="el-menu-item"
                    style="color: rgb(255, 255, 255); border-bottom-color: transparent; background-color: rgb(24, 27, 44);">
                    虚拟车站
                </li>
                <li role="menuitem" tabindex="0" class="el-menu-item"
                    style="color: rgb(255, 255, 255); border-bottom-color: transparent; background-color: rgb(24, 27, 44);">
                    出行迁途
                </li>
                <li role="menuitem" tabindex="0" class="el-menu-item"
                    style="color: rgb(255, 255, 255); border-bottom-color: transparent; background-color: rgb(24, 27, 44);">
                    用户数据
                </li>
                <li role="menuitem" tabindex="0" class="el-menu-item"
                    style="color: rgb(255, 255, 255); border-bottom-color: transparent; background-color: rgb(24, 27, 44);">
                    热力图
                </li>
            </ul>
        </div>
    </div>
</div>
<!--    导航栏结束  -->
<div id="container"></div>
<div class="input-card">
    <h4>轨迹回放控制</h4>
    <div class="input-item">
        <input type="button" class="btn" value="开始动画" id="start" onclick="startAnimation()"/>
        <input type="button" class="btn" value="暂停动画" id="pause" onclick="pauseAnimation()"/>
    </div>
    <div class="input-item">
        <input type="button" class="btn" value="继续动画" id="resume" onclick="resumeAnimation()"/>
        <input type="button" class="btn" value="停止动画" id="stop" onclick="stopAnimation()"/>
    </div>
    <div class="input-item">
        <input type="text" value="39a096b71376b82f35732eff6d95779b"  id="orderId" />
        <input type="button"  onclick="gps()" value="提交"/>
    </div>
</div>
<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=2dcd5f3b01d7415070246a87f562554a"></script>
<script type="text/javascript" src="../static/js/jquery-3.3.1.min.js"></script>
<script>
    var rotationLine = [];
    var polyline
    var passedPolyline
    var marker


    function gps() {
        var orderId = $("#orderId").val()
        $.ajax({
            type: "get",
            url: "http://localhost:9090/track/historyTrackPoints",
            data: {
                orderId: orderId,
            },
            success: function (result) {

                if (result.success){
                    console.log(result)
                    // debugger
                    var  data = result.data
                    for (var i = 0; i < data.length; i++) {
                        rotationLine.push([data[i].lng, data[i].lat]);

                    }
                    console.log(data[0].lng+","+data[0].lat)
                    //画小车车
                    marker = new AMap.Marker({
                        //显示在地图上
                        map: map,
                        //显示在地图上的位置
                        position: [data[0].lng,data[0].lat],
                        //小车车的图片
                        icon: "https://webapi.amap.com/images/car.png",
                        //偏移值 如果不设置默认偏移值为 -10,-34 ，如果为0,0则是为左上角对准所设置的点
                        offset: new AMap.Pixel(-26, -13),
                        // content:"aa",
                        autoRotation: true,
                        angle:-90,
                    });

                    //画路线图
                    polyline = new AMap.Polyline({
                        map: map,
                        path: rotationLine,
                        showDir:true,
                        strokeColor: "#28F",  //线颜色
                        // strokeOpacity: 1,     //线透明度
                        strokeWeight: 6,      //线宽
                        // strokeStyle: "solid"  //线样式
                    });

                    //画走过的路线图
                    passedPolyline = new AMap.Polyline({
                        map: map,
                        // path: lineArr,
                        strokeColor: "#AF5",  //线颜色
                        // strokeOpacity: 1,     //线透明度
                        strokeWeight: 6,      //线宽
                        // strokeStyle: "solid"  //线样式
                    });
                }
            }
        });
    }

    var map = new AMap.Map("container", {
        resizeEnable:true,
        center: [104.07504,30.72672],
        zoom:17
    });

    marker.on('moving', function (e) {
        passedPolyline.setPath(e.passedPath);
    });

    //设置地图自适应可见范围
    map.setFitView();

    function startAnimation () {
        //轨迹回放 动画播放
        marker.moveAlong(rotationLine, 200);
    }

    function pauseAnimation () {
        marker.pauseMove();
    }

    function resumeAnimation () {
        marker.resumeMove();
    }

    function stopAnimation () {
        marker.stopMove();
    }
</script>
</body>
</html>






